<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php

$connect = mysql_connect ("localhost","root","") or die ("Could not connect to DB!");
mysql_select_db ("store",$connect) or die ("could not select DB!");


?>



<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="../../CSS/Divlayouts.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Search Results</title>
<style type="text/css">
#Pannel {
	position:absolute;
	width:989px;
	height:700px;
	z-index:3;
	left: 263px;
	top: 250px;
}
#apDiv1 {
	position:absolute;
	width:166px;
	height:303px;
	z-index:4;
	left: 278px;
	top: 260px;
}
#apDiv2 {
	position:absolute;
	width:170px;
	height:302px;
	z-index:5;
	left: 469px;
	top: 261px;
}
#apDiv3 {
	position:absolute;
	width:179px;
	height:302px;
	z-index:6;
	left: 665px;
	top: 262px;
}
#apDiv4 {
	position:absolute;
	width:185px;
	height:302px;
	z-index:7;
	left: 864px;
	top: 261px;
}
#apDiv5 {
	position:absolute;
	width:167px;
	height:301px;
	z-index:8;
	left: 1075px;
	top: 263px;
}
#apDiv6 {
	position:absolute;
	width:168px;
	height:327px;
	z-index:9;
	left: 273px;
	top: 593px;
}
#apDiv7 {
	position:absolute;
	width:169px;
	height:330px;
	z-index:10;
	left: 470px;
	top: 592px;
}
#apDiv8 {
	position:absolute;
	width:175px;
	height:333px;
	z-index:11;
	left: 669px;
	top: 590px;
}
#apDiv9 {
	position:absolute;
	width:183px;
	height:330px;
	z-index:12;
	left: 866px;
	top: 591px;
}
#apDiv10 {
	position:absolute;
	width:164px;
	height:335px;
	z-index:13;
	left: 1075px;
	top: 589px;
}
#cart {
	position:absolute;
	width:108px;
	height:28px;
	z-index:6;
	left: 822px;
	top: -149px;
}
#apDiv11 {
	position:absolute;
	width:95px;
	height:37px;
	z-index:14;
	left: 33px;
	top: 232px;
}
#apDiv12 {
	position:absolute;
	width:95px;
	height:37px;
	z-index:15;
	left: 41px;
	top: 231px;
}
#apDiv13 {
	position:absolute;
	width:112px;
	height:38px;
	z-index:16;
	left: 41px;
	top: 231px;
}
#apDiv14 {
	position:absolute;
	width:97px;
	height:40px;
	z-index:17;
	left: 48px;
	top: 231px;
}
#apDiv15 {
	position:absolute;
	width:114px;
	height:42px;
	z-index:18;
	left: 28px;
	top: 230px;
}
#apDiv16 {
	position:absolute;
	width:112px;
	height:38px;
	z-index:19;
	left: 31px;
	top: 276px;
}
#apDiv17 {
	position:absolute;
	width:96px;
	height:39px;
	z-index:20;
	left: 505px;
	top: 819px;
}
#apDiv18 {
	position:absolute;
	width:116px;
	height:41px;
	z-index:21;
	left: 32px;
	top: 279px;
}
#apDiv19 {
	position:absolute;
	width:111px;
	height:42px;
	z-index:22;
	left: 40px;
	top: 277px;
}
#apDiv20 {
	position:absolute;
	width:99px;
	height:43px;
	z-index:23;
	left: 1113px;
	top: 814px;
}
#apDiv21 {
	position:absolute;
	width:112px;
	height:43px;
	z-index:24;
	left: 29px;
	top: 280px;
}
#apDiv22 {
	position:absolute;
	width:993px;
	height:163px;
	z-index:14;
	left: 264px;
	top: 962px;
}
</style>
</head>


<body>

<pre><p>                          <a href="../index.php"><img src="../../Resources/eMart logo.png" width="170" height="67" alt="Logo" /></a>                                                                <b><a  style="color:#000; text-decoration:none;" href="customer_support.php">Customer Support</a>  |  <a style="color:#000; text-decoration:none;" href="Policy.php">Privacy Policy</a></b>
                                            Welcome! <a href="login.php">Sign in</a> or <a href="register.php">Register</a></pre>
<div id="DivHR"><hr/></div>
<div  style="background-image:url(../../Resources/Search%20Bar.png)" id="DivBar"></div>
<div id="Pannel" style="background-image:url(../../Resources/Gallery%20Pannel.png); background-repeat:no-repeat">

<div id="cart"><a href="../cart.php"><img src="../../Resources/Mycart.png" width="100" height="25" alt="cart" /></a></div>



</div>


<div id="DivSearchBar"> 
<form name="emartsearch" action="emartsearchresult.php" method="post">
<select name="criteria">
        <option value="1">All Criterias</option>
        <option value="2">Product Name</option>
        <option value="3">Product Code</option>
        <option value="4">Category</option> 

    </select>
    <input type="text" style="width: 400px" value="Enter search term" size="25" maxlength="20" name="parameter" />
        <input type="submit" name="search" value="Search" />
</form></div>

<div id="apDiv1">
<?php
session_start();

$criteria = $_POST['criteria'];
$searchterm = $_POST['parameter'];
//$searchterm = trim($searchterm);

$con = mysql_connect("localhost","root","") or die ("Could not connect to DB!");
mysql_select_db ("web project",$con) or die ("could not select DB!");


switch ($criteria)
{
	case "All Criterias":

			
			$query = "SELECT * FROM products WHERE (ProductCode) OR (ProductName) OR (dep_code) LIKE '%".$searchterm."%'";
			
			//display data from database
			$result = mysql_query($query);
			
			$num_results = mysql_num_rows($result); //Checking the number of rows in the query
		
			if($num_results > 0 )
			{
				
			//Method used to print the output of the query
			print "<table border=1>";
		
		
		while($row = mysql_fetch_array($result))
		{	
			print "<tr>";
			print "<td>";
			echo $row['LightboxImage'];
			print "</td>";
			print"<td>";
			echo $row['ProductCode'];
			print "</td>";
			print"<td>";
			echo $row ['ProductName'];
			print "</td>";
			print"<td>";
			echo $row ['ProductPrice'];
			print "</td>";
			print"<td>";
			echo $row['ProductQuantity'];
			echo "</td>";
			print "</tr>";
		}
		
		print "</table>";
				
				mysql_close($con);
		}
		else
			if($searchterm != NULL)
			{
				print"No items were found matching the keywords '<b>$searchterm</b>'";
			}
			else
			{
	  			print "No items were found as no keywords were entered";
		 	}
	  break;
	  
	
	case "Product Name":
			
			$query = "SELECT*FROM products WHERE ProductName LIKE '%".$searchterm."%'";
			
			//display data from database
			$result = mysql_query($query);
			
			$num_results = mysql_num_rows($result); //Checking the number of rows in the query
		
		if($num_results > 0)
		{
			//Method used to print the output of the query
			
			print "<table border=1>";
			
			while($row = mysql_fetch_array($result))
		{	
			print "<tr>";
			print "<td>";
			echo $row['LightboxImage'];
			print "</td>";
			print"<td>";
			echo $row['ProductCode'];
			print "</td>";
			print"<td>";
			echo $row ['ProductName'];
			print "</td>";
			print"<td>";
			echo $row ['ProductPrice'];
			print "</td>";
			print"<td>";
			echo $row['ProductQuantity'];
			echo "</td>";
			print "</tr>";
		}
		
		print "</table>";
				
				mysql_close($con);
		}
		else
			if($searchterm != NULL)
			{
				print"No items were found matching the keywords '<b>$searchterm</b>'";
			}
			else
			{
	  			print "No items were found as no keywords were entered";
		 	}
	  break;
	 
	case "Category":
	  
			
			$query = "SELECT*FROM products WHERE dep_code LIKE '%".$searchterm."%'";
			
			//display data from database
			$result = mysql_query($query);
			
			$num_results = mysql_num_rows($result); //Checking the number of rows in the query
		
		//Method used to print the output of the query
		
				if($num_results > 0)
		{
			//Method used to print the output of the query
			
			print "<table border=1>";
			
			while($row = mysql_fetch_array($result))
		{	
			print "<tr>";
			print "<td>";
			echo $row['LightboxImage'];
			print "</td>";
			print"<td>";
			echo $row['ProductCode'];
			print "</td>";
			print"<td>";
			echo $row ['ProductName'];
			print "</td>";
			print"<td>";
			echo $row ['ProductPrice'];
			print "</td>";
			print"<td>";
			echo $row['ProductQuantity'];
			echo "</td>";
			print "</tr>";
		}
		
		print "</table>";
				
				mysql_close($con);
		}
		else
			if($searchterm != NULL)
			{
				print"No items were found matching the keywords '<b>$searchterm</b>'";
			}
			else
			{
	  			print "No items were found as no keywords were entered";
		 	}
	  break;
	  
	  
	case "Product Code":
		
		$query = "SELECT*FROM products WHERE ProductCode LIKE '%".$searchterm."%'";
		
		//display data from database
		$result = mysql_query($query);
		
		$num_results = mysql_num_rows($result); //Checking the number of rows in the query
		
		//Method used to print the output of the query
		
				if($num_results > 0)
		{
			//Method used to print the output of the query
			
			print "<table border=1>";
			
			while($row = mysql_fetch_array($result))
		{	
			print "<tr>";
			print "<td>";
			echo $row['LightboxImage'];
			print "</td>";
			print"<td>";
			echo $row['ProductCode'];
			print "</td>";
			print"<td>";
			echo $row ['ProductName'];
			print "</td>";
			print"<td>";
			echo $row ['ProductPrice'];
			print "</td>";
			print"<td>";
			echo $row['ProductQuantity'];
			echo "</td>";
			print "</tr>";
		}
		
		print "</table>";
				
				mysql_close($con);
		}
		else
			if($searchterm != NULL)
			{
				print"No items were found matching the keywords '<b>$searchterm</b>'";
			}
			else
			{
	  			print "No items were found as no keywords were entered";
		 	}
	  break;
	 
	default:
		mysql_close($connect);
		 if (($searchterm == NULL && $criteria == "") || ($searchterm == NULL))
		 {
	  		print "No items were found as no keywords were entered";
		 }
}

?>
</div>
<div id="apDiv22" style="background-image:url(../../Resources/Footer%20Image.png); background-repeat:no-repeat">


</div>
</body>
</html> 